﻿<UserControl x:Class="Tum.PDE.LanguageDSL.Visualization.ViewControl"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="558" 
             TextOptions.TextFormattingMode="Display"
             xmlns:view="clr-namespace:Tum.PDE.LanguageDSL.Visualization.View"
             xmlns:ctrl="clr-namespace:Tum.PDE.LanguageDSL.Visualization.View.Controls"
             xmlns:commands="clr-namespace:Tum.PDE.LanguageDSL.Visualization.Commands">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Styles/TabItemStyle.xaml"/>
                
                <!-- Domain model style -->
                <ResourceDictionary Source="../Resources/Styles/DomainModelTreeStyle.xaml"/>

                <!-- Diagram model style -->
                <ResourceDictionary Source="../Resources/Styles/DiagramModelTreeStyle.xaml"/>

                <!-- Serialization model style + templates -->
                <ResourceDictionary Source="../Resources/Styles/SerializationModelTreeViewStyle.xaml"/>
                
            </ResourceDictionary.MergedDictionaries>

            <commands:CommandReference x:Key="CopyCommandRef" Command="{Binding Path=SelectedItem.CopyCommand}"/>
            <commands:CommandReference x:Key="CutCommandRef" Command="{Binding Path=SelectedItem.CutCommand}"/>
            <commands:CommandReference x:Key="PasteCommandRef" Command="{Binding Path=SelectedItem.PasteCommand}"/>            

            <ControlTemplate TargetType="{x:Type Control}" x:Key="ModelContextTemplate">
                <!--<Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0" Orientation="Horizontal">
                        <Image x:Name="ImageContext" Width="44" Height="44" ToolTip="{Binding Path=DomainElementName, Mode=OneWay}"
                               Source="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/odf.icon.48.png"/>

                        <StackPanel Grid.Row="0" Orientation="Vertical">
                            <TextBlock Margin="3,5,0,5" Text="Model Context" TextDecorations="Underline"/>
                            <TextBlock Margin="3,5,0,0" Text="{Binding Path=DomainElementName, Mode=OneWay}"/>
                        </StackPanel>
                    </StackPanel>
                    <view:ViewContextControl Grid.Row="1"/>
                </Grid>-->
                <view:ViewContextControl />
            </ControlTemplate>

            <ControlTemplate TargetType="{x:Type Control}" x:Key="ExternModelContextTemplate">
                <Grid>
                    <Grid.RowDefinitions>
                        <!--<RowDefinition Height="50"/>
                        <RowDefinition Height="1"/>-->
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <!--<StackPanel Grid.Row="0" Orientation="Horizontal">
                        <Image x:Name="ImageContext" Width="48" Height="48" ToolTip="{Binding Path=DomainElementName, Mode=OneWay}"
                               Source="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/file.icon.48.png"/>

                        <StackPanel Grid.Row="0" Orientation="Vertical">
                            <TextBlock Margin="3,5,0,5" Text="Extern Model Context" TextDecorations="Underline"/>
                            <TextBlock Margin="3,5,0,0" Text="{Binding Path=DomainElementName, Mode=OneWay}"/>
                        </StackPanel>
                    </StackPanel>

                    <Rectangle Grid.Row="1" Height="1" Stroke="Silver" StrokeThickness="1" />-->

                    <TextBlock Grid.Row="2" TextWrapping="WrapWithOverflow" Margin="0,5,0,0"
                                   Text="This ExternModelContext is designed to include a model context in this DSL that was developed in a different DSL. "/>

                    <view:ViewExternLibraryControl Grid.Row="3" DataContext="{Binding Path=ExternModelContextReference, Mode=OneWay}"/>

                </Grid>
            </ControlTemplate>

            <ControlTemplate TargetType="{x:Type Control}" x:Key="LibraryContextTemplate">
                <view:ViewLibraryControl/>
                <!--
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="50"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Grid.Row="0" Orientation="Horizontal">
                        <Image x:Name="ImageContext" Width="48" Height="48" ToolTip="{Binding Path=DomainElementName, Mode=OneWay}"
                               Source="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/database.icon.48.png"/>

                        <StackPanel Grid.Row="0" Orientation="Vertical">
                            <TextBlock Margin="3,5,0,5" Text="Library Model Context" TextDecorations="Underline"/>
                            <TextBlock Margin="3,5,0,0" Text="{Binding Path=DomainElementName, Mode=OneWay}"/>
                        </StackPanel>
                    </StackPanel>
                    <view:ViewLibraryControl Grid.Row="1"/>
                </Grid>-->
            </ControlTemplate>

            <DataTemplate x:Key="ModelContextItem">
                <Control>
                    <Control.Style>
                        <Style TargetType="{x:Type Control}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Path=ModelContextViewType}" Value="ModelContext">
                                    <Setter Property="Template" Value="{StaticResource ModelContextTemplate}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=ModelContextViewType}" Value="ExternModelContext">
                                    <Setter Property="Template" Value="{StaticResource ExternModelContextTemplate}"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding Path=ModelContextViewType}" Value="LibraryContext">
                                    <Setter Property="Template" Value="{StaticResource LibraryContextTemplate}"/>
                                </DataTrigger>                                
                            </Style.Triggers>
                        </Style>
                    </Control.Style>
                </Control>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.InputBindings>
        <KeyBinding Command="{StaticResource CutCommandRef}" Key="X" Modifiers="Control"/>
        <KeyBinding Command="{StaticResource CopyCommandRef}" Key="C" Modifiers="Control"/>
        <KeyBinding Command="{StaticResource PasteCommandRef}" Key="V" Modifiers="Control"/>
    </UserControl.InputBindings>
   
    <Grid>
        <TabControl Background="White" ItemsSource="{Binding Path=ModelContextVMs, Mode=OneWay}" 
                    Margin="1,0,0,0"
                    TabStripPlacement="Top" ContentTemplate="{StaticResource ModelContextItem}"
                    SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" 
                    ItemContainerStyle="{StaticResource TabItemStyleNoGrayBackgroundWithSelection}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" Margin="2.5">
                        <Image x:Name="ImageContext" Width="32" Height="32" ToolTip="{Binding Path=DomainElementName, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality"
                               Source="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/odf.icon.128.png"/>                        
                        <TextBlock x:Name="TextContext" Text="{Binding Path=DomainElementName}" Margin="5,2,2,5" VerticalAlignment="Center" Foreground="Navy"/>
                    </StackPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=ModelContextViewType}" Value="ExternModelContext">
                            <Setter Property="Source" TargetName="ImageContext" Value="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/file.icon.128.png"/>
                            <Setter Property="Foreground" TargetName="TextContext" Value="Maroon"/>
                        </DataTrigger>

                        <DataTrigger Binding="{Binding Path=ModelContextViewType}" Value="LibraryContext">
                            <Setter Property="Source" TargetName="ImageContext" Value="/Tum.PDE.LanguageDSL.Visualization;component/Resources/Images/database.icon.128.png"/>
                            <Setter Property="Foreground" TargetName="TextContext" Value="DarkGreen"/>
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <!--
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="IsSelected" Value="{Binding Path=IsSelected,Mode=TwoWay}"/>
                </Style>
            </TabControl.ItemContainerStyle>-->
        </TabControl>
    </Grid>
</UserControl>